package com.sgb.jicai.view.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.sgb.jicai.R;
import com.sgb.jicai.databinding.ActivityPurchasingContentBinding;
import com.sgb.jicai.entity.JiCaiJoinInQuotedPriceCompanyEntity;
import com.sgb.jicai.view.adapter.PurConListAdapter;
import com.swgk.core.base.AppActivity;

/**
 * 采购内容页面
 */
public class PurchasingContentActivity extends AppActivity {

    private ActivityPurchasingContentBinding binding;
    public static final String DATA_ENTITY = "jicai_id";
    private JiCaiJoinInQuotedPriceCompanyEntity entity;
    private PurConListAdapter adapter;

    public static void start(Context context, JiCaiJoinInQuotedPriceCompanyEntity jiCaiJoinInQuotedPriceCompanyEntity) {
        Intent intent = new Intent();
        intent.putExtra(DATA_ENTITY, jiCaiJoinInQuotedPriceCompanyEntity);
        intent.setClass(context, PurchasingContentActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        super.initView();
        binding = DataBindingUtil.setContentView(PurchasingContentActivity.this, R.layout.activity_purchasing_content);
        binding.ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        DividerItemDecoration divider = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(this, R.drawable.shape_list_divide_joinin_details_jc));
        if (null == adapter) {
            adapter = new PurConListAdapter(this, null);
        }
        binding.recycler.addItemDecoration(divider);
        binding.recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        binding.recycler.setNestedScrollingEnabled(false);
        binding.recycler.setAdapter(adapter);
        binding.recycler.setLoadingMoreEnabled(false);
    }

    @Override
    protected void init() {
        super.init();
        entity = (JiCaiJoinInQuotedPriceCompanyEntity) getIntent().getSerializableExtra(DATA_ENTITY);
        binding.setViewModel(entity);
        //访问数据
        if (null != entity && null != entity.getRecords() && entity.getRecords().size() > 0) {
            adapter.setDatas(entity.getRecords());
        } else {
            adapter.setDatasMayNull(null);
        }
    }

    public void updateView() {

    }


}
